package com.example;

import java.util.concurrent.TimeUnit;

import rx.Observable;
import rx.Observer;
import rx.Subscriber;
import rx.functions.Action1;
import rx.functions.Func3;

public class MyClass {

    public static void main(String[] args){
//        testZip();
//        testTimer();
        testRange();
    }


    private static void testRange() {
        Observable.range(23, 3).subscribe(new Subscriber<Integer>() {
            public void onNext(Integer value) {
                System.out.println("========="+ String.valueOf(value));
            }

            @Override
            public void onCompleted() {
                System.out.println("========="+ "onCompleted");
            }

            @Override
            public void onError(Throwable e) {
                System.out.println("========="+ "onError");
            }
        });
    }

    private static void testTimer(){
        Observable
                .timer(3, TimeUnit.SECONDS)
                .subscribe(new Observer<Long>() {
                    @Override
                    public void onCompleted() {
                        System.out.println("=========");
                    }

                    @Override
                    public void onError(Throwable e) {
                        System.out.println("========="+e.getMessage());
                    }

                    @Override
                    public void onNext(Long aLong) {
                        System.out.println("========="+aLong);
                    }
                });
    }

    private static void testZip(){
        Observable<String> observable1 = Observable.just("zhu", "ying", "ming", "is", "good", "man");
        Observable<Integer> observable2 = Observable.just(5, 6, 7, 8);
        Observable<Integer> observable3 = Observable.just(5, 6, 7, 8);
        Observable.zip(observable1, observable2, observable3, new Func3<String, Integer, Integer, String>() {
            @Override
            public String call(String s, Integer integer, Integer integer2) {
                return s + " == " + integer + " , " + integer2;
            }
        }).subscribe(new Action1<String>() {
            @Override
            public void call(String s) {
                System.out.println("=====" + s);
            }
        });

    }


}
